<template>
  <view>
    <view class="content-container">
		<view class="title-block" />
		<!-- 标题 -->
		<view class="title">
			确认订单
		</view>
		<!-- 商品显示 -->
		<order-goods-card />
		<view class="bottom-buy" @tap="handleToAddOrder()">
			是我的了 ¥ {{totalPrice}} | H {{totalCoin}}
		</view>
    </view>
  </view>
</template>
<script>
  import orderGoodsCard from './order_goods_card.vue'
  export default
  {
    // 组件名称
    name: 'confirm-order',
    // 组件
    components:
    {
		orderGoodsCard
    },
    props:
      {
      },
    // 数据
    data()
      {
        return {
          msg: '确认订单',
		  buy_goods:{
			  goods_id:0,
			  goods_sku_id:0,
			  sale_price:'0.00',
			  coin_price:'0.00',
			  picture:null,
			  spuName:'',
			  skuName:'',
			  selectSkuItem:null,
			  goodsSkuArray:[],
			  //选中的skuIndex
			  selectSkuIndex:null,
			  //购买数量默认为1
			  buy_number:1,
		  }
        }
      },
    // 计算属性
    computed:
      {
		  totalPrice()
		  {
			  let total = this.buy_goods.buy_number * this.buy_goods.sale_price
			  
			  return total.toFixed(2)
		  },
		  totalCoin()
		  {
			  let total = this.buy_goods.buy_number * this.buy_goods.coin_price
			  
			  return total.toFixed(2)
		  }
      },
    // 监听
    watch:
      {
      },
    // 实例创建之前
    beforeCreate()
      {
      },
    // 创建
    created()
      {
      },
    // 挂载之前
    beforeMount()
      {
      },
    // 挂载 --常用
    mounted()
      {
		  const _this = this
		 uni.$once('toBuyGoods',function(data)
		 {
					//console.log(data)
		 			
		 			_this.$set(_this.buy_goods,'goods_id',data.goods_id)
		 			_this.$set(_this.buy_goods,'goods_sku_id',data.goods_sku_id)
		 			_this.$set(_this.buy_goods,'picture',data.picture)
		 			_this.$set(_this.buy_goods,'sale_price',data.sale_price)
		 			_this.$set(_this.buy_goods,'coin_price',data.coin_price)
		 			_this.$set(_this.buy_goods,'spuName',data.spuName)
		 			_this.$set(_this.buy_goods,'skuName',data.skuName)
		 			
		 			if(data.selectSkuIndex !== null)
		 			{
		 				_this.$set(_this.buy_goods,'goodsSkuArray',data.goodsSkuArray)
		 				_this.$set(_this.buy_goods,'selectSkuIndex',data.selectSkuIndex)
		 			}
		 			
		 })
		  
		  uni.$on('prepareGoods',function(data)
		  {
			  //console.log(data)
			  _this.$set(_this.buy_goods,'goods_id',data.goods_id)
			  _this.$set(_this.buy_goods,'goods_sku_id',data.goods_sku_id)
			  _this.$set(_this.buy_goods,'picture',data.picture)
			  _this.$set(_this.buy_goods,'sale_price',data.sale_price)
			  _this.$set(_this.buy_goods,'coin_price',data.coin_price)
			  _this.$set(_this.buy_goods,'spuName',data.spuName)
			  _this.$set(_this.buy_goods,'skuName',data.skuName)
			  _this.$set(_this.buy_goods,'buy_number',data.buy_number)
			  
			  if(data.selectSkuIndex !== null)
			  {
			  	_this.$set(_this.buy_goods,'goodsSkuArray',data.goodsSkuArray)
			  	_this.$set(_this.buy_goods,'selectSkuIndex',data.selectSkuIndex)
			  }
		  })
      },
    // 更新之前
    beforeUpdate()
      {
      },
    // 跟新后
    updated()
      {
      },
    // 销毁之前
    beforeDestroy()
      {
      },
    // 销毁后
    destroyed()
      {
		  uni.$off('prepareGoods');
      },
    // 方法
    methods:
    {
		//添加订单
		handleToAddOrder()
		{
			uni.setStorageSync('buyGoods',this.buy_goods)
			uni.navigateTo({
				url:'/pages/YouHu/V1/user/goods/payGoods/payGoods'
			})
		}
    }
  }
</script>
<style lang='scss' scoped>
 .content-container{
	width: 100%;
	height:auto;
	min-height: 100rpx;
	/* background-color: pink; */
	.title-block{
		width: 100%;
		height:34rpx;
		/* background-color: pink; */
	}
	.title{
		width: 100%;
		height:44rpx;
		font-family: PingFang SC, PingFang SC;
		font-weight: 500;
		font-size: 32rpx;
		color: #1D2129;
		line-height: 44rpx;
		text-align: center;
		font-style: normal;
		text-transform: none;
	}
	.bottom-buy{
		margin-top: 20rpx;
		width: 100%;
		height: 88rpx;
		background: linear-gradient( 133deg, #0D8CE9 0%, #0074FD 77%);
		border-radius: 20rpx 20rpx 0rpx 0rpx;
		font-family: PingFang SC, PingFang SC;
		font-weight: 400;
		font-size: 30rpx;
		color: #FFFFFF;
		line-height: 88rpx;
		text-align: center;
		font-style: normal;
		text-transform: none;
	}
 }
</style>